﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dimine.Core;

namespace DmtViewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "dmt文件(*.dmt)|*.dmt";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                dmDataTableCS datatable = new dmDataTableCS();
                datatable.Load(ofd.FileName);

                int fieldCount = datatable.GetFieldCount();
                for (int i = 0; i < fieldCount; ++i)
                {
                    dmDataTableFieldCS field = datatable.GetField(i);
                    listView1.Columns.Add(field.Name);
                }
                int recordCount = datatable.GetRecordCount();
                for (int i = 0; i < recordCount; ++i)
                {
                    ListViewItem item = listView1.Items.Add(datatable.GetValue(i, 0) + "");
                    for (int j = 1; j < fieldCount; j++)
                    {
                        item.SubItems.Add(datatable.GetValue(i, j) + "");
                    }
                    if (listView1.Items.Count > 100)
                        break;
                }
            }
        }
    }
}
